import { VxeGridPropTypes, VxeTable } from '@/components/VxeTable';
import {} from '@/utils/permission';
import { Tag, Tooltip, Button, Space } from 'ant-design-vue';
import { h } from 'vue';
import {
  DeleteOutlined,
  EditOutlined,
  PauseCircleOutlined,
  PlayCircleOutlined
} from '@ant-design/icons-vue';

export default [
  {
    title: '作业编号',
    type: 'expand',
    field: 'jobDetail.jobId',
    fixed: 'left',
    width: 150,
    slots: {
      default({ row }) {
        return row.jobDetail.jobId;
      },
      content({ row }) {
        return (
          <VxeTable border data={row.jobTriggers} showOverflow="tooltip">
            <vxe-column
              width="140"
              field="triggerId"
              title="触发器编号"
            ></vxe-column>
            <vxe-column
              width="140"
              field="triggerType"
              title="类型"
            ></vxe-column>
            <vxe-column
              width="140"
              field="assemblyName"
              title="程序集"
            ></vxe-column>
            <vxe-column width="140" field="args" title="参数"></vxe-column>
            <vxe-column
              width="140"
              field="description"
              title="描述"
            ></vxe-column>
            <vxe-column width="140" field="status" title="状态">
              {{
                default({ row }) {
                  return [
                    <Tag visible={row.status == 0} color="warning">
                      积压
                    </Tag>,
                    <Tag visible={row.status == 1} color="">
                      就绪
                    </Tag>,
                    <Tag visible={row.status == 2} color="success">
                      正在运行
                    </Tag>,
                    <Tag visible={row.status == 3} color="error">
                      暂停
                    </Tag>,
                    <Tag visible={row.status == 4} color="error">
                      阻塞
                    </Tag>,
                    <Tag visible={row.status == 5} color="">
                      由失败进入就绪
                    </Tag>,
                    <Tag visible={row.status == 6} color="error">
                      归档
                    </Tag>,
                    <Tag visible={row.status == 7} color="error">
                      崩溃
                    </Tag>,
                    <Tag visible={row.status == 8} color="error">
                      超限
                    </Tag>,
                    <Tag visible={row.status == 9} color="error">
                      无触发时间
                    </Tag>,
                    <Tag visible={row.status == 10} color="error">
                      未启动
                    </Tag>,
                    <Tag visible={row.status == 11} color="error">
                      未知作业触发器
                    </Tag>,
                    <Tag visible={row.status == 12} color="error">
                      未知作业处理程序
                    </Tag>
                  ];
                }
              }}
            </vxe-column>
            <vxe-column width="140" field="startTime" title="起始时间" />
            <vxe-column width="140" field="endTime" title="结束时间" />
            <vxe-column width="140" field="lastRunTime" title="最近运行时间" />
            <vxe-column
              width="140"
              field="nextRunTime"
              title="下一次运行时间"
            />
            <vxe-column width="140" field="numberOfRuns" title="触发次数" />
            <vxe-column
              width="140"
              field="maxNumberOfRuns"
              title="最大触发次数"
            />
            <vxe-column width="140" field="numberOfErrors" title="出错次数" />
            <vxe-column
              width="140"
              field="maxNumberOfErrors"
              title="最大出错次数"
            />
            <vxe-column width="140" field="numRetries" title="重试次数" />
            <vxe-column width="140" field="retryTimeout" title="重试间隔ms" />
            <vxe-column width="140" field="startNow" title="立即启动">
              {{
                default({ row }) {
                  const status = row.startNow;
                  const enable = status == true;
                  const color = enable ? 'blue' : 'red';
                  const text = enable ? '是' : '否';
                  return h(Tag, { color: color }, () => text);
                }
              }}
            </vxe-column>
            <vxe-column width="140" field="runOnStart" title="启动时执行一次">
              {{
                default({ row }) {
                  const status = row.runOnStart;
                  const enable = status == true;
                  const color = enable ? 'blue' : 'red';
                  const text = enable ? '是' : '否';
                  return h(Tag, { color: color }, () => text);
                }
              }}
            </vxe-column>
            <vxe-column width="140" field="resetOnlyOnce" title="重置触发次数">
              {{
                default({ row }) {
                  const status = row.resetOnlyOnce;
                  const enable = status == true;
                  const color = enable ? 'blue' : 'red';
                  const text = enable ? '是' : '否';
                  return h(Tag, { color: color }, () => text);
                }
              }}
            </vxe-column>
            <vxe-column
              width="140"
              field="updatedTime"
              title="更新时间"
              align="center"
            />
            <vxe-column title="操作" width="150" fixed="right" show-overflow>
              {{
                default({}) {
                  return [
                    <Space size={2}>
                      <Tooltip title="启动触发器">
                        <Button
                          size="small"
                          type="dashed"
                          icon={<PlayCircleOutlined />}
                          onClick={() => {}}
                        />
                      </Tooltip>
                      <Tooltip title="暂停触发器">
                        <Button
                          size="small"
                          type="dashed"
                          icon={<PauseCircleOutlined />}
                          onClick={() => {}}
                        />
                      </Tooltip>
                      <Tooltip title="编辑触发器">
                        <Button
                          size="small"
                          type="dashed"
                          icon={<EditOutlined />}
                          onClick={() => {}}
                        ></Button>
                      </Tooltip>
                      <Tooltip title="删除触发器">
                        <Button
                          size="small"
                          type="dashed"
                          danger
                          icon={<DeleteOutlined />}
                          onClick={() => {}}
                        ></Button>
                      </Tooltip>
                    </Space>
                  ];
                }
              }}
            </vxe-column>
          </VxeTable>
        );
      }
    }
  },
  {
    title: '组名称',
    field: 'jobDetail.groupName'
  },
  {
    title: '类型',
    field: 'jobDetail.jobType'
  },
  {
    title: '描述',
    field: 'jobDetail.description'
  },
  {
    title: '执行类型',
    field: 'jobDetail.concurrent',
    slots: {
      default: ({ row }) => {
        return row.jobDetail.concurrent ? '并行' : '串行';
      }
    }
  },
  {
    title: '作业创建类型',
    field: 'jobDetail.createType',
    slots: {
      default: ({ row }) => {
        const requestType = row.jobDetail.createType;
        switch (requestType) {
          case 0:
            return h(Tag, { color: 'orange' }, () => '内置');
          case 1:
            return h(Tag, { color: 'orange' }, () => '脚本');
          case 2:
            return h(Tag, { color: 'orange' }, () => 'HTTP请求');
        }
        return requestType;
      }
    }
  },
  {
    title: '额外数据',
    field: 'jobDetail.properties',
    slots: {
      default: ({ row }) => {
        if (row.jobDetail?.createType == 2) {
          return row.jobDetail.properties;
        }
        return row.jobDetail.properties;
      }
    }
  },
  {
    width: 180,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right'
  }
] as VxeGridPropTypes.Columns;
